package com.huitone.gddw.listener;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import com.huitone.gddw.utils.SpringContextUtil;

/**
 * session监听类
 * @author wuluodan
 *
 */
public class SessionListener implements HttpSessionListener {

//	@Autowired
//    private StringRedisTemplate stringRedisTemplate;
	
	@Override
	public void sessionCreated(HttpSessionEvent se) {
		
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		Object userId = se.getSession().getAttribute("userId");
		if (userId != null) {
			StringRedisTemplate stringRedisTemplate = SpringContextUtil.getBean("stringRedisTemplate");
			stringRedisTemplate.delete(userId.toString());
		}
	}

}
